package com.sq.universe.base.entity;

import com.sq.universe.base.constants.BaseConstants;
import lombok.Data;

/**
 * @author 孙乾 2020.05.14
 * 返回结果集合
 */
@Data
public class RespEntity {

    /**
     * 相应消息
     */
    private String message;

    /**
     * 响应状态
     */
    private Integer code;

    /**
     * 相应消息内容
     */
    private Object data;

    public RespEntity(){
        code = BaseConstants.STATUS_SUCCCESS;
    }

    public RespEntity(String message){
        code = BaseConstants.STATUS_SUCCCESS;
        this.message = message;
    }

    public RespEntity(String message,Object object){
        code = BaseConstants.STATUS_SUCCCESS;
        this.message = message;
        this.data = object;
    }

    public RespEntity(String message,Integer code){
        this.code = code;
        this.message = message;
    }

    /**
     * 失败
     */
    public static RespEntity error(String message) {
        RespEntity rb = new RespEntity();
        rb.setCode(500);
        rb.setMessage(message);
        return rb;
    }

    public static RespEntity error(String message,Object data) {
        RespEntity rb = new RespEntity();
        rb.setCode(500);
        rb.setMessage(message);
        rb.setData(data);
        return rb;
    }

    /**
     * 成功
     */
    public static RespEntity success(String message) {
        RespEntity rb = new RespEntity();
        rb.setCode(20000);
        rb.setMessage(message);
        return rb;
    }

    /**
     * 成功
     */
    public static RespEntity success(Object data) {
        RespEntity rb = new RespEntity();
        rb.setCode(20000);
        rb.setMessage("操作成功");
        rb.setData(data);
        return rb;
    }

    /**
     * 失败
     */
    public static RespEntity success(String message,Object data) {
        RespEntity rb = new RespEntity();
        rb.setCode(20000);
        rb.setMessage(message);
        rb.setData(data);
        return rb;
    }
}
